<?php
/**
 * @property-read Zend_Config $_config Social config
 * @property-read YouNet_Model_User $_user
 */
abstract class YouNet_Social_Plugin
{	
	protected $_name;
	protected $_config;
	protected $_id_social;
	protected $_user;
	protected $_id_user;
	protected $_posted_fields = array();
	
	public function __construct($config)
	{
		$this->_config = $config;
	}
	
	public function getName()
	{
		return $this->_name;
	}
	
	public function getAppUrl()
	{
		return $this->_config->url;
	}
	
	public function getAppId()
	{
		return $this->_config->id;
	} 
	
	public function getAppProfileUrl()
	{
		return $this->_config->profileUrl;
	}
	
	/**
	 * 
	 * @return Zend_Config
	 */
	public function getConfig()
	{
		return $this->_config;
	}

	public function getIdSocial()
	{
		return $this->_id_social;
	}
	
	public function getUser()
	{
		return $this->_user;
	}
	
	public function getIdUser()
	{
		return $this->_id_user;
	}
	
	public function getOAuthScope()
	{
		return $this->_config->oauthScope;
	}
	
	public function render($action, $params = array())
	{	
		$front = Zend_Controller_Front::getInstance();
		$directory = $front->getControllerDirectory($this->_name);
		include_once $directory . '/' . $this->_name . 'Controller.php';
		
		$controller_class = $this->_name . '_' . $this->_name . 'Controller';
		$controller = new $controller_class();
		
		return $controller->$action($params);
	}
	
	public function getPostedFields()
	{
		return $this->_posted_fields;
	}
	
	public function getPostedFieldsForUrl()
	{
		$this->getPostedFields();
		$ret = '';		
		foreach ($this->_posted_fields as $field => $value)
		{
			$ret .= '/' . $field . '/' . $value;
		}
		return $ret;
	}
	
	/**
	 * Get a list of fanpages administered by the current user
	 * @return array in the form of
	 * 		[] => array ('id' => <PAGE_ID>, 'name' => <PAGE_NAME>)
	 */
	public function getUserPages()
	{
		return array();
	}
	
	/**
	 * Get list of fanpages in the form array[id] = name
	 * return array
	 */
	public function getPageList()
	{
		return array();
	}
	
	/**
	 * Get a list of fanpage Ids administered by the current user
	 * @return array 
	 */
	public function getUserPageIds()
	{
		return array();
	}
	
	/**
	 * Get fanpage url based on id_page
	 * @param string $id_page
	 * @param string $page_name name of the fanpage
	 * @return string
	 */
	public function getFanPageUrl($id_page, $page_name = null)
	{
		return '';
	}
	
	/**
	 * Wrap the $original_url by Social app url
	 * @param string $original_url
	 * @return string
	 */
	public function url($original_url)
	{
		return $original_url;
	}
	
	/**
	 * Build a fanpage URL using $params
	 * @param array $params
	 * @return string
	 */
	public abstract function pageUrl($params, $id_page = null);
	
	/**
	 * Handle the situation where current user does not have enough privileges to perform a specific action
	 * Common case: redirect user to Social OAuth page
	 * @param string $redirect_url the url to be redirected to after Social Plugin tries to authenticate and authorize the user
	 */
	public abstract function handleFailedAuthorization($redirect_url = '/');
		
	/**
	 * Add user to database if it is the first time user authorizes this app
	 */
	protected abstract function _updateUserDb();
	public abstract function redirect($url);
	public abstract function getIdPage();
	public abstract function getPageName($id_page);
	public abstract function isPageAdmin();
	public abstract function hasLikedPage($id_page = null, $id_social = null);
	
	
	/**
	 * Post a link to a fanpage wall
	 * @param string $url link to be posted
	 * @param string $message message to be posted
	 * @param string $id_page ID of page to be posted
	 * 		if null given, then post to the current fanpage
	 * @return object result
	 */
	public abstract function postUrlToPageWall($url, $message = '', $id_page = null);
	
	public abstract function getShareUrl($url, $name = 'default', $reset = false, $encode = true);

	public abstract function redirectLink($url);

	public abstract function isUseLocalScript();
    
	/**
	 * Get a list of pages are already installed app
	 * @return array array(id => 'id_page', 'name' => 'name_page')
	 */
	public abstract function getListInstalledPages();
    /**
	 * Get a list of albums photo by id_page 
	 * @return array albums photos 
	 */
	public abstract function getAlbumsByIdPage($id_page);
    /**
     * Get information of album
     * @param $id_album
     * @return array information of album 
     */
    public abstract function getAlbumInfo($id_album);
    /**
     * Get album cover photo
     * @param $id_photo
     * @return array information of photo
     */
    public abstract function getPhotoInfo($id_photo);
    /**
     * Get list photo by id album
     * @param $id_album
     * @return array photos 
     */
    public abstract function getAlbumPhotos($id_album);
	
	/**
     * Get info of user permssions
	 * @param mix $id_user Id social user or me
     * @return array|boolean
     */
    public abstract function getUserPermissions($id_user = 'me');
	
	/**
	 * @param array $arrScope List scopes need to get
	 * @param string $redirect_url Redirect url
	 * return void
	 */
	public abstract function requirePermissions(array $arrScope, $redirect_url);
	
	/**
	 * 
	 */
	public abstract function getVisitorInfo();
}
